<?php


namespace app\common\model;

use traits\model\SoftDelete;
use app\common\model\PushRecord;
class Merchant extends Base
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $autoWriteTimestamp = true;

    /**
     * 账户余额币 变化
     * @params $merch_id int 商户id
     * @params $money float 金额 (负数为减少)
     */
    public function changeBalance($merch_id, $money) {

        if (empty($money) || !is_numeric($money) || $money == 0 ) {
            return false;
        }
        if ($money > 0) { // 增加账户币 业务逻辑
            $this->addBalance($merch_id, $money);
        }

        return true;
    }

    /**
     * 增加 账户币 业务
     */
    public function addBalance($merch_id, $money) {

        // 增加商户余额 是否能生成分发规则生效记录
        $push_record_model = new PushRecord();
        $push_record_model->addByMerchs([$merch_id]);
        return true;
    }
}